<style>
	body{
		background: #f5f5f5;
	}
</style>
<script type="text/javascript">
	function countDown(obj,endTime){
		var time_start = new Date().getTime(); //设定当前时间
		var time_end =  parseInt(endTime); //设定目标时间
		// 计算时间差
		var time_distance = time_end - time_start;
		if(time_distance < 0){  // 日期已过
			console.log(obj);
			$(obj).text("已到期");//加载数据后，发现已经过期了，没有倒计时的必要
			return false;
		}
		// 天
		var int_day = Math.floor(time_distance/86400000);
		time_distance -= int_day * 86400000;
		// 时
		var int_hour = Math.floor(time_distance/3600000);
		time_distance -= int_hour * 3600000;
		// 分
		var int_minute = Math.floor(time_distance/60000);
		time_distance -= int_minute * 60000;
		// 秒
		var int_second = Math.floor(time_distance/1000);
		// 时分秒为单数时、前面加零
		if(int_day < 10 && int_day > 0){
			int_day = "0" + int_day;
		}
		if(int_hour < 10){
			int_hour = "0" + int_hour;
		}
		if(int_minute < 10){
			int_minute = "0" + int_minute;
		}
		if(int_second < 10){
			int_second = "0" + int_second;
		}
		if(int_day<=0 && int_hour<=0 && int_minute <=0 && int_second<=0){
			console.log(obj);
			$(obj).text("已到期");//加载数据后，发现已经过期了，没有倒计时的必要
			return false;
		}
		// 显示时间
		if(int_day>0){
			var result = parseInt(int_day)+"天"+int_hour+"小时"+int_minute+"分"+int_second+'秒';
		}else{
			var result = int_hour+"小时"+int_minute+"分"+int_second+'秒';
		}
		$(obj).text(result);
		// 设置定时器
		setTimeout("countDown("+"'"+obj+"'"+","+endTime+")",1000);
	}
</script>
<div class="sectionY">
	<a href="javascript:history.back()">
		<img src="__PUBLIC__/home/images/a4.png" class="a1" alt="">
	</a>
	<p class="p1">转让记录</p>
</div>
<div class="kong1"></div>
<div class="qiangg_section1">
	<div class="qiangg_section1_1 qiangg_section1_1x clearfix">
		<ul  class="condition">
			<li class="select"  data-types="1">
				<a href="javascript:;">
					<p class="p1">待转让</p>
					<span class="s1"></span>
				</a>
			</li>
			<li data-types="2">
				<a href="javascript:;">
					<p class="p1">转让中</p>
					<span class="s1"></span>
				</a>
			</li>
			<li  data-types="3">
				<a href="javascript:;">
					<p class="p1">已完成</p>
					<span class="s1"></span>
				</a>
			</li>
			<li>
				<a href="{:url('Rent/transfer',['types'=>4])}">
					<p class="p1">取消/申诉</p>
					<span class="s1"></span>
				</a>
			</li>
		</ul>
	</div>
</div>
<div class="qiangg_section2 content">
	<div class="content1"></div>
</div>

<script>
	var params = {
		page: 0,
		page_size: 10,
		types:1
	};
	var mm;
	$(function () {
		params.types = $(".condition").find('.select').data('types');
		mm = $('.content').dropload({
			scrollArea: window,
			domUp: {
				domClass: 'dropload-up',
				domRefresh: '<div class="dropload-refresh" style="color: #ccc">↓下拉刷新</div>',
				domUpdate: '<div class="dropload-update" style="color: #ccc">↑释放更新</div>',
				domLoad: '<div class="dropload-load" style="color: #ccc"><span class="loading"></span>加载中</div>'
			},
			domDown: {
				domClass: 'dropload-down',
				domRefresh: '<div class="dropload-refresh" style="color: #ccc">↑上拉加载更多</div>',
				domLoad: '<div class="dropload-load" style="color: #ccc"><span class="loading"></span>加载中</div>',
				domNoData: '<div class="dropload-noData" style="color: #ccc">暂无更多数据</div>'
			},
			loadUpFn: function (me) {
				params.page = 1;
				var _html = '';
				$.ajax({
					url: '{:url(\'Rent/ajaxmorerenttransfer\')}',
					data: params,
					dataType: "JSON",
					type: "POST",
					success: function (res) {
						var data = res;
						if (data.length > 0) {
							_html = formatList(data);
						}
						$('.content1').html(_html);
						// 每次数据加载完，必须重置
						me.resetload();
						// 重置页数，重新获取loadDownFn的数据
						page = 1;
						// 解锁loadDownFn里锁定的情况
						me.unlock();
						me.noData(false);
					},
					error: function (res) {
						alert(res);
					}
				})
			},
			loadDownFn: function (me) {
				params.page++;
				var _html = '';
				$.ajax({
					url: '{:url(\'Rent/ajaxmorerenttransfer\')}',
					data: params,
					dataType: "JSON",
					type: "POST",
					success: function (res) {
						var data = res;
						if (data.length > 0) {
							_html = formatList(data);
						} else {
							// 锁定
							me.lock();
							// 无数据
							me.noData();
						}
						// 插入数据到页面，放到最后面
						$('.content1').append(_html);
						// 每次数据插入，必须重置
						me.resetload();
					},
					error: function (res) {
						alert(res);
					}
				})
			},
			threshold: 50
		});
		$(".condition li").click(function () {
			params.types = $(this).data('types');
			$(this).addClass('select').siblings().removeClass('select')
			mm.opts.loadUpFn(mm)
		})
	});

	function formatList(data) {
		var _html = '';
		$.each(data, function (i, v) {
			_html += '\n' +
					'\t<div class="list">\n' +
					'\t\t<div class="a1 clearfix">\n' +
					'\t\t\t<p class="p1">订单编号:'+v.ctime2+'-'+v.id+'</p>\n';

			if(v.peiduistatus<2){
				_html += '\t\t\t<p class="p2">待转让</p>\n';
			}else{
				if(v.paystatus==1){
					_html += '\t\t\t<p class="p2">转让中</p>\n';
				}
				if(v.paystatus==2){
					_html += '\t\t\t<p class="p2">已完成</p>\n';
				}
			}
					_html += '\t\t</div>\n' +
					'\t\t<div class="a2">\n' +
					'\t\t\t<p class="p1">类型：'+v.title+'</p>\n' +
					'\t\t\t<p class="p1">应收费用：'+v.price+'</p>\n' +
					'\t\t\t<p class="p1">合约收益：'+v.daynum+'天/'+v.earnpercent+'%</p>\n' +
					'\t\t\t<p class="p1">抢购时间：'+v.ctime+'</p>\n' +
					'\t\t</div>\n' +
					'\t\t<div class="a3">\n';
			var url = "{:url('Rent/transfercon')}?id="+data[i]['id'];
			_html += '\t\t\t<a href="'+url+'" class="a1">订单详情</a>\n';
			if(v.paystatus==1){
				var getmoney = '{:url("Rent/suregetmoney")}?id='+v.id;
				_html +='<a data-href="'+getmoney+'" class="a2" href=\'javascript:;\' onclick=\'checkPayPwd(this)\'>确认收款</a>';
			}
					_html += '\t\t</div>\n' +
					'\t</div>';
		})
		return _html;
	}
</script>

<script>
	//检验交易密码
	function checkPayPwd(o) {
		var url = $(o).data('href');
		layer.prompt({'title':'请输入交易密码'}, function (res) {
			$.post('{:url("Rent/checkPwd")}', {pwd:res}, function (r) {
				if(r.result_code == 0){
					console.log("success=>",r)
					location.href=url
				}else{
					console.log("error=>",r)
					layer.msg(r.result_info)
				}
			})
		})
	}
</script>